<%--Created by IntelliJ IDEA.
User: admin
Date: 2017/4/12
Time: 10:48
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--解析表达式--%>
<%@ page isELIgnored="false" %>
<%--引入jstl--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--引入springMVC form--%>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%--分页--%>
<%@ taglib prefix="page" uri="/xianzhiOA/pageTag" %>
<%--权限控制--%>
<%@ taglib prefix="p" uri="/xianzhiOA/powerTag" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Basic -->
    <meta charset="UTF-8"/>
    <title>项目计划一览</title>
    <script type="application/javascript">
        function edit() {
            document.getElementById("planForm").action = "${pageContext.request.contextPath}/Plan/planEdit.emp";
            document.getElementById("planId").value = null;
            document.getElementById("planForm").submit();
        }
        function pToSub(page) {
            if(page!=undefined){
                var pageInp = document.getElementById("page");
                pageInp.value = page;
                var form = document.getElementById("planForm");
                form.submit();
            }
        }
        //用ajax根据姓名查询员工
        function selByOffName(type) {
            var empNameI = "";
            var empNameD = "";
            if (type == "off"){
                empNameD = document.getElementById("empNameDO");
                empNameI = document.getElementById("empNameIO").value;
                if(empNameI == null || empNameI == ""){
                    document.getElementById("planOfficial").value = "";
                }
            }else {
                empNameD = document.getElementById("empNameDA");
                empNameI = document.getElementById("empNameIA").value;
                if(empNameI == null || empNameI == ""){
                    document.getElementById("planAudit").value = "";
                }
            }
            empNameD.innerHTML = "";
            var empName = "";
            $.ajax({
                url: '${pageContext.request.contextPath}/Plan/selByEmpName.emp',
                data: {empName: empNameI},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.length>0) {
                        for (i = 0; i < data.length; i++) {
                            if (type == "off"){
                                empName += "<div onclick='sendOffName("+i+")' id='"+i+"' style='margin:0;padding:0;width: 98px;background-color: white'>"+data[i].empName+"</div><input id='pId"+i+"' type='hidden' value='"+data[i].empId+"'/>";
                            }else {
                                empName += "<div onclick='sendAudName("+i+")' id='"+i+"' style='margin:0;padding:0;width: 98px;background-color: white'>"+data[i].empName+"</div><input id='pId"+i+"' type='hidden' value='"+data[i].empId+"'/>";
                            }
                        }
                        empNameD.innerHTML = empName;
                        empNameD.style.display = "block";
                    }else {
                        empNameD.style.display = "none";
                    }
                }
            })
        }
        //选择负责人，并保存负责人id
        function sendOffName(type) {
            //把负责人姓名放到input里
            document.getElementById("empNameIO").value = document.getElementById(type).innerHTML;
            //把负责人id保存到planOfficial里
            document.getElementById("planOfficial").value = document.getElementById("pId"+type).value;
            //清空div
            document.getElementById("empNameDO").innerHTML = "";
            document.getElementById("empNameDO").style.display = "none";
        }
        //选择审核人，并保存负责人id
        function sendAudName(type) {
            //把审核人的姓名放到input里
            document.getElementById("empNameIA").value = document.getElementById(type).innerHTML;
            //把审核人的id保存到planAudit里
            document.getElementById("planAudit").value = document.getElementById("pId"+type).value;
            //清空div
            document.getElementById("empNameDA").innerHTML = "";
            document.getElementById("empNameDA").style.display = "none";
        }
        function deleteCheck(id) {
            if (confirm("确定要删除吗")) {
                window.location.href = "${pageContext.request.contextPath}/Plan/deletePlan.emp?planId="+id;
            }
        }
        var ii=0;
        function describe(type) {
            var showInfo = document.getElementById("showInfo"+type);
            var show = document.getElementById(type);
            if (ii==0) {
                show.innerHTML = "计划描述："+showInfo.value;
                showInfo.style.backgroundColor="#fffff1";
                showInfo.innerHTML="退出描述";
                ii++;
            }else {
                show.innerHTML = "";
                showInfo.style.backgroundColor="#fff";
                ii--;
            }
        }
    </script>
</head>
<body>
<!--头部开始-->
<jsp:include page="headerBack.jsp"></jsp:include>
<!-- 导航 -->
<jsp:include page="leftBack.jsp"></jsp:include>
<!--内容页-->
<div class="main">
    <!--内容页头部-->
    <div class="page-header">
        <div class="pull-left">
            <ol class="breadcrumb visible-sm visible-md visible-lg">
                <li><a href="${pageContext.request.contextPath}/Login/goHomePage"><i class="icon fa fa-home"></i>主页</a></li>
                <li class="active"><i class="fa fa-pencil"></i>基本信息</li>
            </ol>
        </div>
        <div class="pull-right">
            <h2>主页</h2>
        </div>
    </div>
    <!--form表单-->
    <sf:form id="planForm" action="${pageContext.request.contextPath}/Plan/selPlanAll.emp" modelAttribute="plan"
               method="post" class="search1">
        <input type="hidden" id="page" name="page" value="${page}"/>
        <input type="hidden" id="pages" name='pages' value="${pages}"/>
        <input type="hidden" id="jj"/>
        <c:if test="${msg != null}"><h3 style="color: #0FB492">${msg}</h3></c:if>
        <sf:input type="hidden" path="planId"/>
        <div style="height: 40px">
            <p:power jspPower="计划：添加">
                <button onclick="edit()" class="three btn btn-primary">添加</button>
            </p:power>
            <a href="${pageContext.request.contextPath}/Plan/selPlanAll.emp" class="three btn btn-primary">重置</a></div>
        <sf:input style="width: 140px" path="projectName" type="text" placeholder="按归属项目搜索..."/>
        <sf:input style="width: 140px" path="planName" type="text" placeholder="按计划名称搜索..."/>
        <input id="var" style="width: 120px" name="planRank" <c:if test="${plan.planRank!=0}">value="${plan.planRank}" </c:if> type="text" placeholder="按计划级别搜索..."
               size="10" oninput="if (! /^\d+$/ig.test(this.value)){this.value='';}"/>
        <sf:input style="width: 140px" path="superName" type="text" placeholder="按上级计划搜索..."/>
        <input type="text" name="official" value="${plan.official}" style="margin-bottom: 0px;width: 100px" placeholder="按负责人搜索..."/>
        <input type="text" name="audit" value="${plan.audit}" style="margin-bottom: 0px;width: 100px" placeholder="按审核人搜索..."/>
        <input style="width: 92px" class="sang_Calender" name="begina" type="text" value="<fmt:formatDate type="both" value="${begina}" pattern="yyyy-MM-dd"/>" placeholder="开始时间...">
        <input style="width: 92px" class="sang_Calender" name="beginb" type="text" value="<fmt:formatDate type="both" value="${beginb}" pattern="yyyy-MM-dd"/>" placeholder="结束时间..."><br/>
        <input style="width: 150px" class="sang_Calender" name="beginc" type="text" value="${beginc}" placeholder="创建时间...">~
        <input style="width: 150px" class="sang_Calender" name="endc" type="text" value="${endc}" placeholder="创建时间...">
        <button type="submit" class="one"><span class="fa fa-search"></span></button>
    </sf:form>
    <c:if test="${planList.isEmpty()}"><h3 style="text-align: center">计划信息不存在</h3></c:if>
    <c:if test="${!planList.isEmpty()}">
    <!--表格-->
        <div class="well">
            <table class="table" id="now">
                <thead>
                <tr>
                    <th class="vvv">归属项目</th>
                    <th class="vv">计划名称</th>
                    <th class="vv">计划级别</th>
                    <th class="vv">开始时间</th>
                    <th class="vv">结束时间</th>
                    <th class="vv">上级计划</th>
                    <th class="vv">负责人</th>
                    <th class="vv">审核人</th>
                    <th class="vvv">创建时间</th>
                    <th class="vv">计划描述</th>
                    <p:power jspPower="计划：删除">
                        <th class="vv">删除</th>
                    </p:power>
                    <p:power jspPower="计划：修改">
                        <th class="vv">修改</th>
                    </p:power>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="p" items="${planList}">
                    <tr>
                        <td>${p.project.projectName}</td>
                        <td>${p.planName}</td>
                        <td>${p.planRank}</td>
                        <td><fmt:formatDate type="both" value="${p.planStart}" pattern="yyyy-MM-dd"/></td>
                        <td><fmt:formatDate type="both" value="${p.planEnd}" pattern="yyyy-MM-dd"/></td>
                        <td>${p.plan.planName}</td>
                        <td>${p.emp.empName}</td>
                        <td>${p.emp1.empName}</td>
                        <td><fmt:formatDate type="both" value="${p.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                        <td><button id="showInfo${p.planId}" onclick="describe(${p.planId})" value="${p.planDescribe}" type="button">查看描述</button>
                        </td>
                        <p:power jspPower="计划：删除">
                            <td>
                                <a onclick="deleteCheck(${p.planId})" role="button" data-toggle="modal"><i class="fa fa-times"></i></a>&nbsp;
                            </td>
                        </p:power>
                        <p:power jspPower="计划：修改">
                            <td>
                                <a href="${pageContext.request.contextPath}/Plan/planEdit.emp?planId=${p.planId}" role="button" data-toggle="modal"><i class="fa fa-pencil"></i></a>
                            </td>
                        </p:power>
                    </tr>
                    <tr>
                        <td colspan="12" id="${p.planId}"></td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </c:if>
    <c:if test="${pages > 1}">
        <div style="float: right">
            <ul class="pagination">
                <page:paging length="10" page="${page}" pages="${pages}"/>
            </ul>
        </div>
    </c:if>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/dist/backEnd/js/datetime.js"></script>
</body>
</html>